import Transaction from "https://cdn.jsdelivr.net/npm/@konghayao/promise-transaction/dist/promiseTransaction.browser.js";
import throttle from "https://cdn.jsdelivr.net/npm/lodash-es/throttle.js";
import renderReport from "../utils/Report.js";
import { HitAction } from "./components/HitAction.js";
import renderVideo from "./components/renderVideo.js";
export default new Transaction([
    [
        "see Flower",
        () => {
            app.stage.Flower.alpha = 1;
            app.userLock = false;
        },
    ],
    [
        "Drag Event",
        () => {
            const Hand = app.stage.Drug;
            HitAction(
                Hand,
                () => {
                    // Flower
                    Record.updateState((state) => state.drug++);
                    Hand.anime(Hand.dragMessage.lockPlace);
                },
                () => {
                    Music.Drug.play();
                }
            );
        },
    ],
    [
        "Fei Event",
        () => {
            const Hand = app.stage.Fei;
            HitAction(
                Hand,
                () => {
                    // Flower
                    Record.updateState((state) => state.fei++);
                    Hand.anime(Hand.dragMessage.lockPlace);
                },
                () => {
                    Music.Fei.play();
                }
            );
        },
    ],
    [
        "Water Event",
        () => {
            const Hand = app.stage.Water;
            HitAction(
                Hand,
                () => {
                    // Flower
                    Record.updateState((state) => state.water++);
                    Hand.anime(Hand.dragMessage.lockPlace);
                },
                () => {
                    Music.Water.play();
                }
            );
        },
    ],
    [
        "Sound Event",
        () => {
            const Hand = app.stage.Sound;
            Hand.on(
                "pointerup",
                throttle(() => {
                    const volume = window.Howler.volume();
                    Hand.changeStates(volume ? "off" : "on");
                    app.stage.Sound.updateTexture();
                    window.Howler.volume(volume ? 0 : 1);
                }, 200)
            );
        },
    ],
    [
        "Next Event",
        () => {
            const Hand = app.stage.Next;
            let lock = false;
            Hand.on("pointerup", async () => {
                if (lock) return;
                lock = true;
                await background.ChangeDarkAndLight();
                lock = false;
                Record.updateState((state) => (state.day += state.step));
            });
        },
    ],
    [
        "Menu Event",
        () => {
            const Hand = app.stage.Menu;
            renderVideo();
            Hand.on("pointerup", async () => {
                mui("#sheet1").popover("toggle");
            });
        },
    ],
    [
        "Exam Event",
        () => {
            const Hand = app.stage.Exam;
            Hand.on("pointerup", async () => {
                renderReport();
            });
        },
    ],
    [
        "Zoom Event",
        () => {
            const Hand = app.stage.Zoom;

            HitAction(Hand, () => {
                // Flower
                console.log("Zoom");
                Hand.anime(Hand.dragMessage.lockPlace);
                window.Zoom();
            });
        },
    ],
]);
